const { HTTP } = require('../../utils/http');
const { api } = require('../../utils/api');
const { request } = new HTTP();
const app = getApp();

Page({
  data: {
    active: 0,
    tabs: [
      {id: 0, title: '心动足迹'},
      {id: 1, title: '无感的人'}
    ],
    userInfo: {},
    visible: false,
    successVisible: false,
    days: '1'
  },
  
  onLoad() {
    this._getUserInfo();
  },
  buy() {
    this.setData({
      visible: true
    })
  },
  vipClose() {
    this.setData({
      visible: false,
      successVisible: false
    })
    this._getUserInfo();
  },
  successOpen(event) {
    const { detail: {index} } = event;
    const actions = {
      '0': '36',
      '1': '11',
      '2': '1'
    }
    this.setData({
      visible: false,
      successVisible: true,
      days: actions[index]
    })
  },
  onClick(event) {
    this.setData({
      active: event.detail.index
    })
  },
  onClickLeft() {
    wx.navigateBack({
      delta: 1
    });
  },
  async _getUserInfo() {
    const {returnCode = '', bean = {}} = await request({
      url: api.getUser,
      method: 'get',
      data: {}
    });
    if (returnCode === '0000') {
      this.setData({userInfo: bean.user })
    }
  },
})
